package com.eastfair.security.feign;

import com.eastfair.auth.api.UserAccountServiceFeign;
import com.eastfair.auth.dto.UserAccountDto;
import com.eastfair.auth.vo.RoleVo;
import com.eastfair.core.base.R;
import com.eastfair.el.ElParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static com.eastfair.core.base.R.SUCCESS_CODE;

@Component
public class UserResolverServiceImpl implements UserResolverService {
    @Autowired
    UserAccountServiceFeign userAccountServiceFeign;

    @Override
    public List<String> getAllPermission(Long userId) {
        ElParam elParam = new ElParam();
        elParam.setObj(userId);
        R<List<String>> r = userAccountServiceFeign.getPermissionOfUserId(elParam);
        if (SUCCESS_CODE == r.getCode()) {
            return r.getData();
        }
        return null;
    }

    @Override
    public List<RoleVo> getAllRole(Long userId) {
        R<List<RoleVo>> r = userAccountServiceFeign.getRoleOfUserId(userId);
        if (SUCCESS_CODE == r.getCode()) {
            return r.getData();
        }
        return null;
    }
}
